﻿
@{
    ViewBag.Title = "访客进出";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script src="~/Content/UI/js/select-ui.min.js"></script>
<script type="text/javascript">
    $(function () {
        $(".select3").uedSelect({
            width: 300
        });
    })

</script>
<div class="place">
    <span>位置：</span>
    <ul class="placeul">
        <li><a href="#">首页</a></li>
        <li><a href="#">访客记录</a></li>
    </ul>
</div>
<div class="formbody">
    <ul class="seachform">
        <li>
            <label>访客姓名:</label><input name="" type="text" class="dfinput" id="NickName" />
        </li>
        <li>
            <label>设备名称:</label><div class="vocation" style="width:300px">
                <select class="select3" id="MobileId">
                    <option value="@Guid.Empty">全部</option>
                    @{
                        var mobiles = (List<MyData.Models.Mobile>)ViewBag.Mobiles;
                        foreach (var mobile in mobiles)
                        {
                            <option value="@mobile.Id">@mobile.Name</option>
                        }

                    }
                </select>
            </div>

        </li>
    </ul>
    <ul class="seachform">
        <li>
            <label>开始日期:</label>
            <input type="text" class="dfinput Wdate" id="StartDate" style="height:34px" placeholder="开始日期" onFocus="WdatePicker()" value="@DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd")" />
        </li>
        <li>
            <label>结束日期:</label>
            <input type="text" class="dfinput Wdate" id="EndDate" style="height:34px" placeholder="结束日期" onFocus="WdatePicker()" value="@DateTime.Now.ToString("yyyy-MM-dd")" />
        </li>
    </ul>
    <ul class="seachform">
        <li>

            <label>&nbsp;</label>
            <input name="" id="ok" type="button" class="scbtn" value="查询" />
         
            <label>&nbsp;</label>
            <input name="" id="batchDelete" type="button" class="scbtn" value="批量删除" />
        </li>
    </ul>


</div>
<div class="table-content">
    <table id="table" class="tablelist"></table>
</div>

<script type="text/javascript">
    $(function () {

        var $table = $('#table'), $ok = $('#ok');
        $ok.click(function () {
            $table.bootstrapTable('refresh');
        });
        function queryParams(params) {
            $('#toolbar').find('input[name]').each(function () {
                params[$(this).attr('name')] = $(this).val();
            });
            //params["UserName"] = $("#UserName").val();
            params["NickName"] = $("#NickName").val();
            params["MobileId"] = $("#MobileId").val();
            params["StartDate"] = $("#StartDate").val();
            params["EndDate"] = $("#EndDate").val();
            return params;
        }

        function responseHandler(res) {
            return res.rows;
        }
        $('#table').bootstrapTable({
            url: '/Visitor/GetVisitorRecord',
            //url: '/api/Document/GetList',
            pagination: true,
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 30,                       //每页的记录行数（*）
            pageList: [10],        //可供选择的每页的行数（*）
            //search: true,   //是否显示表格搜索，此搜索是客户端搜索
            striped: true,
            queryParams: queryParams,
            //responseHandler:responseHandler,
            toolbar: "#toolbar",
            columns: [{
                checkbox: true
            }, {
                field: 'Number',
                title: '序号',
                align: 'center',
                width: 50,
                formatter: function (value, row, index) {
                    //return index + 1;
                    var pageSize = $('#table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                    var pageNumber = $('#table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                    return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                }
            }, {
                field: 'DepartName',
                title: '邀约部门'
            }, {
                field: 'RoleName',
                title: '邀约人员'
            },
            {
                field: 'MobileName',
                title: '设备名称'
                },
                {
                    field: 'NickName',
                    title: '访客姓名'
                },
                  {
                      field: 'TurnOverStr',
                      title: '进出门'
                  },
                 {
                     field: 'Similar',
                     title: '相似度'
                 },
                  {
                      field: 'CreateDate',
                      title: '开门日期'
                  },
            {
                field: 'CreatedTimeStr',
                title: '开门时间'
            }, {
                field: 'Id',
                title: '操作',
                formatter: function (value, row) {
                    return '<a onclick="fnView(\'' + value + '\')" class="tablelink">查看</a> <a onclick="fnDelete(\'' + value + '\')" class="tablelink">删除</a> ';
                }
            },]
        });
        $("#add").click(function () {
            layer.open({
                type: 2,
                area: ['600px', '300px'],
                content: 'AdminUserView'
            });

        });
        $("#batchDelete").click(function () {
            layer.confirm('确定删除吗？', {
                btn: ['确定', '取消'] //按钮
            }, function (index) {
                var temp = $('#table').bootstrapTable("getSelections");
                var array = [];
                for (var i = 0; i < temp.length; i++) {
                    array.push(temp[i].Id);
                }
                $.post("../AccessRecord/AccessRecordBatchDelete", { Ids: array }, function (result) {
                    if (result.state == 1) {
                        layer.msg('操作成功');
                        layer.close(index);
                        $("#table").bootstrapTable('refresh');
                    }
                    else {
                        parent.layer.msg(result.message);
                    }
                })
            }, function (index) {
                layer.close(index);
            });

        });
    })
    function fnView(id)
    {
        window.layer.open({
            type: 2,
            area: ['600px', '500px'],
            fixed: true,
            maxmin: true,
            content: '@Url.Action("PhotoView", "AccessRecord")?Id='+id
        });
    }
    function fnDelete(id) {
        layer.confirm('确定删除吗？', {
            btn: ['确定', '取消'] //按钮
        }, function (index) {
            $.post("../AccessRecord/AccessRecordDelete", { Id: id }, function (result) {
                if (result.state == 1) {
                    layer.msg('操作成功');
                    layer.close(index);
                    $("#table").bootstrapTable('refresh');
                }
                else {
                    parent.layer.msg(result.message);
                }
            })
        }, function (index) {
            layer.close(index);
        });

    }

    function fnExport() {
        window.open("../AccessRecord/ExcelImport1")
    }


</script>


